//
//  LSBaseViewController.m
//  LookScore
//
//  Created by warrior on 2018/7/18.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSBaseViewController.h"
#import "LSUserGuideViewController.h"
#import "LSBaseTabBarController.h"
#import "XYSideViewController.h"
#import "LSMineVController.h"
@interface LSBaseViewController ()
@property (nonatomic, strong) LSMineVController * leftVC;
@end

@implementation LSBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LaunchImage"]];
    [self.view addSubview:imageView];
    imageView.sd_layout
    .leftEqualToView(self.view)
    .rightEqualToView(self.view)
    .topEqualToView(self.view)
    .bottomEqualToView(self.view);
    [self loadConfig];
}
- (void)loadConfig{
    [LSHttpEnclosureTool GET:LSConfig parameters:nil resBlock:^(id responseObject) {
        if (responseObject) {
            BOOL config;
            
//            MyLog(@"Config -- %@",responseObject);
            if ([responseObject isEqual:@(0)]) {
                config = NO;
            }else{
                config = YES;
            }
            [[NSUserDefaults standardUserDefaults] setBool:config forKey:@"isOk"];
            [self joinUserGuide];
            
        }else{
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isOk"];
//            MyLog(@"error");
//            MyLog(<#...#>)
            [self joinUserGuide];
        }
    }];
    
}

-(void)joinUserGuide{
    //1.获取文件路径
    NSString *docPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *path=[docPath stringByAppendingPathComponent:@"data.archiver"];
    NSString *flag =[NSKeyedUnarchiver unarchiveObjectWithFile:path];
    if (![flag isEqualToString:@"firstStart"]) {
        //1.获取文件路径
        NSString *docPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        //2、添加储存的文件名
        NSString *path  = [docPath stringByAppendingPathComponent:@"data.archiver"];
        //3、将一个对象保存到文件中
        [NSKeyedArchiver archiveRootObject:@"firstStart" toFile:path];
        
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isStartFristLoginApp"];
        LSUserGuideViewController *userGuideVC= [[LSUserGuideViewController alloc] init];
//        self.view.window.rootViewController = userGuideVC;
        [UIApplication sharedApplication].keyWindow.rootViewController = userGuideVC;
    }else{
        
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isStartFristLoginApp"];
        //左侧菜单
        self.leftVC = [[LSMineVController alloc] init];
        //创建滑动菜单
        LSBaseTabBarController *rootVC = [[LSBaseTabBarController alloc] init];
        XYSideViewController *rootViewController = [[XYSideViewController alloc] initWithSideVC:self.leftVC currentVC:rootVC];
//        [self.view.window addSubview:rootViewController.view];
//        self.view.window.rootViewController = rootViewController;
        
        [UIApplication sharedApplication].keyWindow.rootViewController = rootViewController;
    }
//    self.view
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
